package com.qf.aop2204.exhandler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;

/**
 * 添加了ARestControllerAdvice注解的类就是全局异常处理器了
 */
@RestControllerAdvice
public class MyExHandler {
    @ExceptionHandler(Exception.class)
    public HashMap<String,Object> handleEx(Exception e){
        HashMap<String, Object> map = new HashMap<>();
        map.put("code","-1");
        map.put("msg",e.getMessage());
        return map;
    }
}
